import bs4
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("https://www.csdn.net/tags/MtTagg2sMDkxLWJsb2cO0O0O.html").read()

#bs
bsObj = BeautifulSoup(html.read(),'html.parser')
div=bsObj.find("div",class_="collect-and-boutique")  #find_all
# len(div)
div1=div.select('div')[0]
p=div1.select('span')[1]
text=p.get_text()
text



#xpath
from lxml import etree
selector=etree.HTML(html) #将源码转化为能被XPath匹配的格式
print(html)
# selector.xpath(表达式) #返回为一列表
                    # /html/body/div[2]/div[2]/div[1]/div[1]/span[2]   从浏览器复制的xpath
num1 =selector.xpath("/html/body/div[1]/div[2]/div[1]/div[1]/span[2]/text()")
# num1 =selector.xpath("/html/body/div/div/div/div/span[2]/text()")
num1
type(num1)
len(num1)